home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / c-lang / vbcc.lha / vbcc / main.c < prev    next >
C/C++ Source or Header  |  1996-05-15  |  20KB  |  577 lines

  1. /*  $VER: vbcc (main.c) V0.3    */
  2.  
  3. #include "vbc.h"
  4.  
  5. int endok=1;
  6. int line,errors;
  7.  
  8. char errfname[100]; /*  VORSICHT: Diese Konstante kommt nochmal vor */
  9.  
  10. char *multname[]={"","s"};
  11. void raus(void)
  12. /*  Beendet das Programm                                            */
  13. {
  14.     if(DEBUG) printf("raus()\n");
  15.     if(!endok) printf("unexpected end of file\n");
  16.     if(errors) printf("%d error%s found!\n",errors,multname[errors>1]);
  17.     while(nesting>=0) leave_block();
  18.     if(in[0]&&(c_flags[17]&USEDFLAG)) fclose(in[0]);
  19.     if(ppout) fclose(ppout);
  20.     if(out) fclose(out);
  21.     if(ic1) fclose(ic1);
  22.     if(ic2) fclose(ic2);
  23.     if(!(c_flags[17]&USEDFLAG)) pp_free();
  24.     if(endok&&!errors) exit(EXIT_SUCCESS); else exit(EXIT_FAILURE);
  25. }
  26.  
  27. int eof;
  28.  
  29. void translation_unit(void)
  30. /*  bearbeitet translation_unit                                     */
  31. /*  hier z.Z. nur provisorisch                                      */
  32. {
  33.     while(1){
  34.         killsp();
  35.         if(c_flags[18]&USEDFLAG){
  36.             if(*s==EOF) raus();
  37.             fputs(string,ppout);fputc('\n',ppout);
  38.             s=string;*s=0;
  39.         }else{
  40.             if(eof||(!isalpha((unsigned char)*s)&&*s!='_')){
  41.                 if(!eof) error(0);
  42.                 raus();
  43.             }
  44.             endok=0;
  45.             var_declaration();
  46.             endok=1;
  47.         }
  48.     }
  49. }
  50.  
  51. void dontwarn(char *p)
  52. /*  schaltet flags fuer Meldung auf DONTWARN    */
  53. {
  54.     int i;
  55.     if(*p!='=') error(4,"-dontwarn");
  56.     i=atoi(p+1);
  57.     if(i>=err_num) error(159,i);
  58.     if(i<0){
  59.         for(i=0;i<err_num;i++)
  60.             if(!(err_out[i].flags&(ANSIV|FATAL)))
  61.                 err_out[i].flags|=DONTWARN;
  62.         return;
  63.     }
  64.     if(err_out[i].flags&(ANSIV|FATAL)) error(160,i);
  65.     err_out[i].flags|=DONTWARN;
  66. }
  67. void warn(char *p)
  68. /*  schaltet Warnung fuer Meldung ein           */
  69. /*  wenn Nummer<0 sind alle Warnungen ein       */
  70. {
  71.     int i;
  72.     if(*p!='=') error(4,"-warn");
  73.     i=atoi(p+1);
  74.     if(i>=err_num) error(159,i);
  75.     if(i<0){
  76.         for(i=0;i<err_num;i++) err_out[i].flags&=~DONTWARN;
  77.         return;
  78.     }else err_out[i].flags&=~DONTWARN;
  79. }
  80.  
  81. extern char *copyright;
  82.  
  83. int main(int argc,char *argv[])
  84. {
  85.     int i,j,fname=0;
  86.     c_flags_val[9].f=dontwarn;
  87.     c_flags_val[10].f=warn;
  88.     for(i=1;i<argc;i++){
  89.         if(*argv[i]!='-'){  /*  kein Flag   */
  90.             if(fname){
  91.                 error(1);
  92.             }else fname=i;
  93.         }else{
  94.             int flag=0;
  95.             for(j=0;j<MAXCF;j++){
  96.                 size_t l;
  97.                 if(!c_flags_name[j]) continue;
  98.                 l=strlen(c_flags_name[j]);
  99.                 if(l>0&&!strncmp(argv[i]+1,c_flags_name[j],l)){
  100.                     flag=1;
  101.                     if((c_flags[j]&(USEDFLAG|FUNCFLAG))==USEDFLAG){error(2,argv[i]);break;}
  102.                     c_flags[j]|=USEDFLAG;
  103.                     if(c_flags[j]&STRINGFLAG){
  104.                         if(argv[i][l+1]!='='){error(3,argv[i]);}
  105.                         c_flags_val[j].p=&argv[i][l+2];
  106.                     }
  107.                     if(c_flags[j]&VALFLAG){
  108.                         if(argv[i][l+1]!='='){error(4,argv[i]);}
  109.                         c_flags_val[j].l=atol(&argv[i][l+2]);
  110.                     }
  111.                     if(c_flags[j]&FUNCFLAG) c_flags_val[j].f(&argv[i][l+1]);
  112.                 }
  113.             }
  114.             for(j=0;j<MAXGF;j++){
  115.                 size_t l;
  116.                 if(!g_flags_name[j]) continue;
  117.                 l=strlen(g_flags_name[j]);
  118.                 if(l>0&&!strncmp(argv[i]+1,g_flags_name[j],l)){
  119.                     flag=1;
  120.                     if((g_flags[j]&(USEDFLAG|FUNCFLAG))==USEDFLAG){error(2,argv[i]);break;}
  121.                     g_flags[j]|=USEDFLAG;
  122.                     if(g_flags[j]&STRINGFLAG){
  123.                         if(argv[i][l+1]!='='){error(3,argv[i]);}
  124.                         g_flags_val[j].p=&argv[i][l+2];
  125.                     }
  126.                     if(g_flags[j]&VALFLAG){
  127.                         if(argv[i][l+1]!='='){error(4,argv[i]);}
  128.                         g_flags_val[j].l=atol(&argv[i][l+2]);
  129.                     }
  130.                     if(g_flags[j]&FUNCFLAG) g_flags_val[j].f(&argv[i][l+1]);
  131.                 }
  132.             }
  133.             if(!flag){error(5,argv[i]);}
  134.         }
  135.     }
  136.     if(!(c_flags[6]&USEDFLAG)) printf(copyright);
  137.     if(!(c_flags[17]&USEDFLAG)) pp_init();
  138.     if(!(c_flags[8]&USEDFLAG)) c_flags_val[8].l=10; /* max. Fehlerzahl */
  139.     if(!fname){error(6);}
  140.     inname=argv[fname];
  141.     strcpy(errfname,inname);    /*  das hier ist Muell - wird noch geaendert    */
  142.     if(!init_cg()) exit(EXIT_FAILURE);
  143.     if(c_flags[17]&USEDFLAG){
  144.         in[0]=fopen(inname,"r");
  145.         if(!in[0]) {error(7,inname);}
  146.     }else{
  147.         if(!pp_include(inname)) error(7,inname);
  148.     }
  149.     if(!(c_flags[18]&USEDFLAG)&&!(c_flags[5]&USEDFLAG)){
  150.         out=open_out(inname,"asm");
  151.         if(!out){
  152.             if(c_flags[17]&USEDFLAG){
  153.                 fclose(in[0]);
  154.             }else{
  155.                 pp_free();
  156.             }
  157.             exit(EXIT_FAILURE);
  158.         }
  159.     }
  160.     if(c_flags[2]&USEDFLAG) ic1=open_out(inname,"ic1");
  161.     if(c_flags[3]&USEDFLAG) ic2=open_out(inname,"ic2");
  162.     if(c_flags[18]&USEDFLAG) ppout=open_out(inname,"i");
  163.     if(c_flags[4]&USEDFLAG) DEBUG=c_flags_val[4].l; else DEBUG=0;
  164.     switch_count=0;break_label=0;
  165.     *string=0;s=string;line=0;
  166.     killsp();
  167.     nesting=-1;enter_block();
  168.     translation_unit();
  169. }
  170.  
  171. void prd(FILE *o,struct Typ *p)
  172. /* Gibt einen Typ auf dem Bildschirm aus    */
  173. {
  174.     int f;
  175.     if(!p) {fprintf(o,"empty type ");return;}
  176.     f=p->flags;
  177. /*    fprintf(o,"(Sizeof=%d,flags=%d)",szof(p),f);*/
  178.     if(f&UNCOMPLETE) {fprintf(o,"incomplete ");f&=~UNCOMPLETE;}
  179.     if(f&CONST) {fprintf(o,"const ");f&=~CONST;}
  180.     if(f&STRINGCONST) {fprintf(o,"string-const ");f&=~STRINGCONST;}
  181.     if(f&VOLATILE) {fprintf(o,"volatile ");f&=~VOLATILE;}
  182.     if(f&UNSIGNED) {fprintf(o,"unsigned ");f&=~UNSIGNED;}
  183.     if(f==FUNKT) {fprintf(o,"function with parameters (");
  184.                   prl(o,p->exact);
  185.                   fprintf(o,") returning ");prd(o,p->next);return;}
  186.     if(f==STRUCT){fprintf(o,"struct with components {");
  187.                   if(p->flags&UNCOMPLETE) fprintf(o,"%s} ",(char *)p->exact);
  188.                    else {prl(o,p->exact);fprintf(o,"} ");}
  189.                   return;
  190.     }
  191.     if(f==UNION) {fprintf(o,"union with components {");
  192.                   if(p->flags&UNCOMPLETE) fprintf(o,"%s} ",(char *)p->exact);
  193.                    else {prl(o,p->exact);fprintf(o,"} ");return;}
  194.     }
  195.     if(f==POINTER) {fprintf(o,"pointer to ");prd(o,p->next);return;}
  196.     if(f==ARRAY) {fprintf(o,"array [size %d] of ",p->size);prd(o,p->next);return;}
  197.     fprintf(o,"%s",typname[f]);
  198. }
  199. void prl(FILE *o,struct struct_declaration *p)
  200. /* Gibt eine struct_declaration auf dem Bildschirm aus */
  201. {
  202.     int i;
  203.     for(i=0;i<p->count;i++) {fprintf(o," %d.:",i); prd(o,p->sl[i].styp);}
  204. }
  205. void freetyp(struct Typ *p)
  206. /* Gibt eine Typ-Liste frei, aber keine struct_declaration oder so */
  207. {
  208.     int f;struct Typ *merk;
  209.     if(DEBUG&8){printf("freetyp: ");prd(stdout,p);printf("\n");}
  210.     while(p){
  211.         merk=p->next;
  212.         f=p->flags&15;
  213.         if(merk&&f!=ARRAY&&f!=POINTER&&f!=FUNKT){ierror(0);return;}
  214.         free(p);
  215.         p=merk;
  216.     }
  217. }
  218. void cpbez(char *m)
  219. /* kopiert den naechsten Bezeichner von s nach m */
  220. {
  221.     if(DEBUG&128) printf("Before cpbez:%s\n",s);
  222.     while(isalpha((unsigned char)*s)||isdigit((unsigned char)*s)||*s=='_') *m++=*s++;
  223.     *m++=0;
  224.     if(DEBUG&128) printf("After cpbez:%s\n",s);
  225. }
  226. void cpnum(char *m)
  227. /* kopiert die naechste int-Zahl von s nach m   */
  228. /* muss noch erheblich erweiter werden          */
  229. {
  230.     if(DEBUG&128) printf("Before cpnum:%s\n",s);
  231.     while(isdigit((unsigned char)*s)) *m++=*s++;
  232.     *m++=0;
  233.     if(DEBUG&128) printf("After cpnum:%s\n",s);
  234.  
  235. }
  236. void killsp(void)
  237. /*  Ueberspringt Fuellzeichen                   */
  238. /*  noch einige unschoene Dinge drin            */
  239. {
  240.     int r;
  241.     if(DEBUG&128) printf("Before killsp:%s\n",s);
  242.     if(eof) raus();
  243.     while(isspace((unsigned char)*s)){
  244. /*        if(*s=='\n') {line++;if(DEBUG&1) printf("Line %d\n",line);}*/
  245.         s++;
  246.     }
  247.     if(*s==0){
  248.         do{
  249.             if(c_flags[17]&USEDFLAG) r=(fgets(string,MAXINPUT,in[0])!=0);
  250.                 else                 r=pp_nextline();
  251.             if(!r){
  252.                 /*raus();*/
  253.                 if(DEBUG&1) printf("nextline/fgets returned 0\n");
  254.                 s=string;*s=0;
  255.                 eof=1;
  256.                 return;
  257.             }else{
  258.                 line++;
  259.                 if(DEBUG&1) printf("Line %d\n",line);}
  260.                 if(!strncmp("#pragma",string,7)) error(163);
  261.                 if(!strncmp("#pragma only-inline on",string,22)){
  262.                     if(DEBUG&1) printf("only-inline on\n");
  263.                     only_inline=1;
  264.                 }
  265.                 if(!strncmp("#pragma only-inline off",string,23)){
  266.                     if(DEBUG&1) printf("only-inline off\n");
  267.                     only_inline=2;
  268.                 }
  269.                 if(!strncmp("#pragma type ",string,13)){
  270.                 /*  Typ eines Ausdrucks im Klartext ausgeben    */
  271.                     np tree;
  272.                     s=string+13;
  273.                     tree=expression();
  274.                     if(tree&&type_expression(tree)){
  275.                         printf("type of %s is:\n",string+13);
  276.                         prd(stdout,tree->ntyp);printf("\n");
  277.                     }
  278.                     if(tree) free_expression(tree);
  279.  
  280.                 }
  281.                 if(!strncmp("#pragma tree ",string,13)){
  282.                 /*  gibt eine expression aus    */
  283.                     np tree;
  284.                     s=string+13;
  285.                     tree=expression();
  286.                     if(tree&&type_expression(tree)){
  287.                         printf("tree of %s is:\n",string+13);
  288.                         pre(stdout,tree);printf("\n");
  289.                     }
  290.                     if(tree) free_expression(tree);
  291.                 }
  292.                 if(string[0]=='#'&&isspace((unsigned char)string[1])&&isdigit((unsigned char)string[2])){
  293.                     sscanf(string+2,"%d \" %[^\"]",&line,errfname);
  294.                     if(DEBUG&1) printf("new line: %d (file=%s)\n",line,errfname);
  295.                     line--;
  296.                 }
  297.                 if(!strncmp("#line ",string,6)){
  298.                     sscanf(string+6,"%d \" %[^\"]",&line,errfname);
  299.                     if(DEBUG&1) printf("new line: %d (file=%s)\n",line,errfname);
  300.                     line--;
  301.                 }
  302.             s=string;
  303.         }while(*s=='#');
  304.         killsp();
  305.     }
  306.     if(DEBUG&128) printf("After killsp:%s\n",s);
  307. }
  308. int szof(struct Typ *t)
  309. /*  liefert die benoetigte Groesse eines Typs in Bytes      */
  310. /*  maschinenabhaengig                                      */
  311. {
  312.     int i=t->flags,j,size,m,f;
  313. /*    if(type_uncomplete(t)){
  314.         error(176);
  315.         return(0);
  316.     }*/
  317.     if(i&UNCOMPLETE) return(0);
  318.     if((i&15)==POINTER) return(4);
  319.     if((i&15)==ARRAY) return((t->size)*szof(t->next));
  320.     if((i&15)==UNION){
  321.         for(j=0,size=0;j<t->exact->count;j++){
  322.             m=szof(t->exact->sl[j].styp);
  323.             if(m==0) return(0);
  324.             if(m>size) size=m;
  325.         }
  326.         return(((size+align[UNION]-1)/align[UNION])*align[UNION]); /* align */
  327.     }
  328.     if((i&15)==STRUCT){
  329.         for(j=0,size=0;j<t->exact->count;j++){
  330.             m=szof(t->exact->sl[j].styp);
  331.             if(m==0) return(0);
  332.             f=(t->exact->sl[j].styp->flags)&15;
  333.             size=((size+align[f]-1)/align[f])*align[f];
  334.             size+=m;
  335.         }
  336.         return(((size+align[STRUCT]-1)/align[STRUCT])*align[STRUCT]);
  337.     }
  338.     if(DEBUG&2) printf("sizeof(%d)=%d\n",i&15,sizetab[i&15]);
  339.     return(sizetab[i&15]);
  340. }
  341. void enter_block(void)
  342. /*  Setzt Zeiger/Struckturen bei Eintritt in neuen Block    */
  343. {
  344.     if(nesting>=MAXN){error(9,nesting);return;}
  345.     nesting++;
  346.     if(DEBUG&1) printf("enter block %d\n",nesting);
  347.     first_ilist[nesting]=last_ilist[nesting]=0;
  348.     first_sd[nesting]=last_sd[nesting]=0;
  349.     first_si[nesting]=last_si[nesting]=0;
  350.     first_var[nesting]=last_var[nesting]=0;
  351.     if(nesting==1){
  352.         first_llist=last_llist=0;
  353.         first_clist=last_clist=0;
  354.         merk_varf=merk_varl=0;
  355.         merk_ilistf=merk_ilistl=0;
  356.         merk_sif=merk_sil=0;
  357.         merk_sdf=merk_sdl=0;
  358.         afterlabel=0;
  359.     }
  360. }
  361. void leave_block(void)
  362. /*  Setzt Zeiger/Struckturen bei Verlassen eines Blocks     */
  363. {
  364.     int i;
  365.     for(i=1;i<=MAXR;i++)
  366.         if(regbnesting[i]==nesting) regsbuf[i]=0;
  367.  
  368.     if(nesting<0){error(10);return;}
  369.     if(DEBUG&1) printf("leave block %d\n",nesting);
  370.     if(nesting>0){
  371.         if(merk_varl) merk_varl->next=first_var[nesting]; else merk_varf=first_var[nesting];
  372.         if(last_var[nesting]) merk_varl=last_var[nesting];
  373.         if(merk_sil) merk_sil->next=first_si[nesting]; else merk_sif=first_si[nesting];
  374.         if(last_si[nesting]) merk_sil=last_si[nesting];
  375.         if(merk_sdl) merk_sdl->next=first_sd[nesting]; else merk_sdf=first_sd[nesting];
  376.         if(last_sd[nesting]) merk_sdl=last_sd[nesting];
  377.         if(merk_ilistl) merk_ilistl->next=first_ilist[nesting]; else merk_ilistf=first_ilist[nesting];
  378.         if(last_ilist[nesting]) merk_ilistl=last_ilist[nesting];
  379.     }
  380.     if(nesting==1){
  381.         if(merk_varf) gen_vars(merk_varf);
  382.         if(first_llist) free_llist(first_llist);
  383.         if(first_clist) free_clist(first_clist);
  384.         if(merk_varf) free_var(merk_varf);
  385.         if(merk_sif) free_si(merk_sif);
  386.         if(merk_sdf) free_sd(merk_sdf);
  387.         if(merk_ilistf) free_ilist(merk_ilistf);
  388.     }
  389.     if(nesting==0){
  390.         if(first_var[0]) gen_vars(first_var[0]);
  391.         if(first_var[0]) free_var(first_var[0]);
  392.         if(first_sd[0]) free_sd(first_sd[0]);
  393.         if(first_si[0]) free_si(first_si[0]);
  394.         if(first_ilist[0]) free_ilist(first_ilist[0]);
  395.     }
  396.     nesting--;
  397. }
  398. void pra(FILE *f,struct argument_list *p)
  399. /*  Gibt argument_list umgekehrt auf Bildschirm aus             */
  400. {
  401.     if(p->next){ pra(f,p->next);fprintf(f,",");}
  402.     if(p->arg) pre(f,p->arg);
  403. }
  404. void pre(FILE *f,np p)
  405. /*  Gibt expression auf Bildschirm aus                          */
  406. {
  407.     int c;
  408.     c=p->flags;
  409.     if(p->sidefx) fprintf(f,"/");
  410.     if(p->lvalue) fprintf(f,"|");
  411.     if(c==CALL){fprintf(f,"call-function(");pre(f,p->left);fprintf(f,")(");
  412.                 if(p->alist) pra(f,p->alist);
  413.                 fprintf(f,")");return;}
  414.     if(c==CAST){fprintf(f,"cast(");pre(f,p->left);
  415.                 fprintf(f,"->");prd(f,p->ntyp);
  416.                 fprintf(f,")");return;}
  417.     if(c==MEMBER){if(p->identifier) fprintf(f,".%s",p->identifier);return;}
  418.     if(c==IDENTIFIER){if(p->identifier) fprintf(f,"%s",p->identifier);
  419.         fprintf(f,"+");printval(f,&p->val,LONG,1); return;}
  420.     fprintf(f,"%s(",ename[c]);
  421.     if(p->left) pre(f,p->left);
  422.     if(p->right){
  423.         fprintf(f,",");
  424.         pre(f,p->right);
  425.     }
  426.     fprintf(f,")");
  427.     if(c==CEXPR||c==PCEXPR){fprintf(f,"(value="); printval(f,&p->val,p->ntyp->flags,1); fprintf(f,")");}
  428. }
  429. void printval(FILE *f,union atyps *p,int t,int verbose)
  430. /*  Gibt atyps aus                                      */
  431. {
  432.     if(t==CHAR){if(verbose)fprintf(f,"C");vlong=zc2zl(p->vchar);printzl(f,vlong);}
  433.     if(t==(UNSIGNED|CHAR)){if(verbose)fprintf(f,"UC");vulong=zuc2zul(p->vuchar);printzul(f,vulong);}
  434.     if(t==SHORT){if(verbose)fprintf(f,"S");vlong=zs2zl(p->vshort);printzl(f,vlong);}
  435.     if(t==(UNSIGNED|SHORT)){if(verbose) fprintf(f,"US");vulong=zus2zul(p->vushort);printzul(f,vulong);}
  436.     if(t==FLOAT){if(verbose)fprintf(f,"F");vdouble=zf2zd(p->vfloat);printzd(f,vdouble);}
  437.     if(t==DOUBLE){if(verbose)fprintf(f,"D");printzd(f,p->vdouble);}
  438.     if(t==INT){if(verbose)fprintf(f,"I");vlong=zi2zl(p->vint);printzl(f,vlong);}
  439.     if(t==LONG){if(verbose)fprintf(f,"L");printzl(f,p->vlong);}
  440.     if(t==(UNSIGNED|INT)){if(verbose)fprintf(f,"UI");vulong=zui2zul(p->vuint);printzul(f,vulong);}
  441.     if(t==(UNSIGNED|LONG)){if(verbose)fprintf(f,"UL");printzul(f,p->vulong);}
  442.     /*  das hier ist nicht wirklich portabel    */
  443.     if(t==POINTER){if(verbose)fprintf(f,"P");vulong=zp2zul(p->vpointer);printzul(f,vulong);}
  444. }
  445. void pric2(FILE *f,struct IC *p)
  446. /*  Gibt ein IC aus */
  447. {
  448.     if(p->next&&p->next->prev!=p) {ierror(0);exit(EXIT_FAILURE);}
  449.     if(p->code>=LABEL&&p->code<=BRA){
  450.         if(p->code==LABEL) fprintf(f,"L%d",p->typf);
  451.         else fprintf(f,"\t\t%s L%d",ename[p->code],p->typf);
  452.     }else{
  453.         fprintf(f,"\t\t%s ",ename[p->code]);
  454.         if(p->typf&UNSIGNED) fprintf(f,"unsigned ");
  455.         if(p->typf) fprintf(f,"%s ",typname[p->typf&15]);
  456.         probj(f,&p->q1,p->typf,1);
  457.         if(p->q2.flags){fprintf(f,",");probj(f,&p->q2,p->typf,1);}
  458.         if(p->z.flags){fprintf(f,"->");probj(f,&p->z,p->typf,1);}
  459.         if(p->code==ASSIGN||p->code==PUSH||p->code==POP) fprintf(f," size=%d",p->q2.reg);
  460.         if((p->code==SAVEREGS||p->code==RESTOREREGS)&&p->q1.reg) fprintf(f," except %s",regnames[p->q1.reg]);
  461.     }
  462.     fprintf(f,"\n");
  463. }
  464. void pric(FILE *f,struct IC *p)
  465. /*  Gibt IC-Liste auf dem Bildschirm aus                */
  466. {
  467.     while(p){
  468.         pric2(f,p);
  469. /*        if(p->q1.am||p->q2.am||p->z.am) ierror(0);*/
  470.         p=p->next;
  471.     }
  472. }
  473.  
  474. char *errstr[]={"","warning","error"};
  475.  
  476. void error(int errn,...)
  477. /*  Behandelt Ausgaben wie Fehler und Meldungen */
  478. {
  479.     int type=0;
  480.     va_list vl;
  481.     if(err_out[errn].flags&DONTWARN) return;
  482.     va_start(vl,errn);
  483.     if(err_out[errn].flags&WARNING) type=1;
  484.     if(err_out[errn].flags&ERROR) type=2;
  485.     if(c_flags[7]&USEDFLAG){
  486.         if(err_out[errn].flags&ANSIV) type=2; else type=0;
  487.     }
  488.     if(type){
  489.         {if(eof) printf(">EOF\n"); else printf(">%s",string);}
  490.         if(!(c_flags[17]&USEDFLAG)){
  491.             printf("\n");
  492.             printf("%s %d in line %d of \"%s\": ",errstr[type],errn,linenr,filename[incnesting]);
  493.         }else{
  494.             printf("%s %d in line %d of \"%s\": ",errstr[type],errn,line,errfname);
  495.         }
  496.     }
  497.     if(type||(err_out[errn].flags&MESSAGE)){
  498.         vprintf(err_out[errn].text,vl);
  499.         printf("\n");
  500.     }
  501.     va_end(vl);
  502.     if(type==2){
  503.         errors++;
  504.         if(c_flags_val[8].l&&c_flags_val[8].l<=errors)
  505.             {printf("Maximum number of errors reached!\n");raus();}
  506.     }
  507.     if(err_out[errn].flags&FATAL){printf("aborting...\n");raus();}
  508. }
  509. void printzl(FILE *f,zlong x)
  510. /*  Konvertiert zlong nach ASCII                        */
  511. /*  basiert noch einigermassen auf                      */
  512. /*  Zweierkomplementdarstellung (d.h. -MIN>MAX)         */
  513. /*  Ausserdem muss max(abs(long))<=max(unsigned long)   */
  514. {
  515.     zlong zl;zulong zul;
  516.     zl=l2zl(0L);
  517.     if(zlleq(x,zl)&&!zleq(x)){
  518.         fprintf(f,"-");zl=zul2zl(t_max[LONG]);
  519.         if(zlleq(x,zlneg(zl))&&!zleqto(x,zlneg(zl))){
  520.         /*  aufpassen, da -x evtl. >LONG_MAX    */
  521.             zul=t_max[LONG];
  522.             x=zladd(x,zl);
  523.         } else zul=ul2zul(0UL);
  524.         x=zlneg(x);
  525.         vulong=zl2zul(x);
  526.         zul=zuladd(zul,vulong);
  527.     }else zul=zl2zul(x);
  528.     printzul(f,zul);
  529. }
  530. void printzul(FILE *f,zulong x)
  531. /*  Konvertiert zulong nach ASCII                       */
  532. {
  533.     zulong zul;unsigned long l;
  534.     if(DEBUG&64) printf("printzul:%lu\n",x);
  535.     zul=ul2zul(10UL);
  536.     if(!zuleq(zuldiv(x,zul))) printzul(f,zuldiv(x,zul));
  537.     zul=zulmod(x,zul);l=zul2ul(zul);
  538.     fprintf(f,"%c",(int)(l+'0'));
  539. }
  540. void printzd(FILE *f,zdouble x)
  541. /*  Konvertiert zdouble nach ASCII, noch nicht fertig   */
  542. {
  543.     fprintf(f,"sorry, floating point not yet");
  544. }
  545. FILE *open_out(char *name,char *ext)
  546. /*  Haengt ext an name an und versucht diese File als output zu oeffnen */
  547. {
  548.     char *s,*p;FILE *f;
  549.     s=(char *)mymalloc(strlen(name)+strlen(ext)+2);
  550.     strcpy(s,name);
  551.     p=s+strlen(s);
  552.     while(p>=s){
  553.         if(*p=='.'){*p=0;break;}
  554.         p--;
  555.     }
  556.     strcat(s,".");
  557.     strcat(s,ext);
  558.     f=fopen(s,"w");
  559.     if(!f) printf("Couldn't open <%s> for output!\n",s);
  560.     free(s);
  561.     return(f);
  562. }
  563. void *mymalloc(size_t size)
  564. /*  Belegt Speicher mit Abfrage     */
  565. {
  566.     void *p;static int safe;
  567.     /*  Um ein Fehlschlagen bei size==0 zu vermeiden; nicht sehr schoen,    */
  568.     /*  aber das einfachste...                                              */
  569.     if(size==0) size=1;
  570.     if(!(p=malloc(size))){
  571.         error(12);
  572.         raus();
  573.     }
  574.     return(p);
  575. }
  576.  
  577.